<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:og="http://java.sun.com/jsf/composite"
	xmlns:p="http://primefaces.org/ui" class="no-js">

<ui:composition template="startTemplate.xhtml">

	<ui:define name="title">
		<h:outputText value="#{i18n.contracts}" />
	</ui:define>
	
	<ui:define name="content">
	    
	<!-- **************************************** Contract table **************************************** -->
	
		<div class="span32">
			<h:form id="contractForm" prependId="false">	
				<p:growl id="contractGrowl" />
					
				<p:dataTable id="dataTableAllContract" value="#{listBean.listContract}" var="c">  			    
				    <f:facet name="header">
				    	<h:outputText value="#{i18n.listContractLabel}" />			    	
				    </f:facet>
				    
				    <p:column style="width:2%">  
			        	<p:commandLink id="contractLink" ajax="true" action="#{contractBean.viewDetail}"
			        		update=":detailContractForm:panelDetailContract">		            	
			            	<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" /> 						 
							<f:setPropertyActionListener target="#{contractBean.contractView}" value="#{c}" /> 									          
					    </p:commandLink>   
			        </p:column>	
			        		      				     
				    <p:column headerText="#{i18n.lastNameLabel}">  
			            <h:outputText value="#{c.name}" />  
			        </p:column>
			        
			        <p:column headerText="#{i18n.applicationLabel}">			        	         
					   	<h:outputText value="#{c.application.name}" /> 					    
			        </p:column>	
			        	
			        <f:facet name="footer">
				    	<p:commandButton id="showAddContract" value="#{i18n.addContractLabel}" icon="ui-icon-plus"
							type="button" onclick="newContractDlg.show()" />    
				    </f:facet>   
				</p:dataTable>  			
			</h:form>
		</div>
			
	<!-- **************************************** Dialog new contract **************************************** -->
	
	    <h:form id="createContractForm">			     					      
		    <p:dialog id="newContractDialog" header="#{i18n.newContractLabel}" widgetVar="newContractDlg" 
		    	dynamic="true" showEffect="clip" hideEffect="scale">					        
		        <h:panelGrid id="newContractPanel" columns="2" styleClass="panel">					
					
					<h:outputLabel id="contractIdLabel" for="contractId"
						value="#{i18n.contractIdLabel} " />						
					<h:inputText id="contractId" value="#{contractBean.contractNew.idContract}">
						<f:passThroughAttribute name="required" value="true" />					
					</h:inputText>
					
					<h:outputLabel id="contractNameLabel" for="contractName"
						value="#{i18n.contractNameLabel} " />						
					<h:inputText id="contractName" value="#{contractBean.contractNew.name}">
						<f:passThroughAttribute name="required" value="true" />					
					</h:inputText>
					
					<h:outputLabel id="contractStartDateLabel" for="contractStartDate"
						value="#{i18n.startDateLabel}" />
					<p:calendar id="contractStartDate" value="#{contractBean.contractNew.startDate}" 
						pattern="dd/MM/yyyy" mode="popup" size="19" required="true" requiredMessage="#{i18n.requiredStartDate}" >					
						<f:convertDateTime pattern="dd/MM/yyyy" />
						<f:passThroughAttribute name="required" value="true" />					
					</p:calendar>
					
					<h:outputLabel id="contractEndDateLabel" for="contractEndDate"
						value="#{i18n.endDateLabel}" />
					<p:calendar id="contractEndDate" value="#{contractBean.contractNew.endDate}" 
						pattern="dd/MM/yyyy" mode="popup" size="19" required="true" requiredMessage="#{i18n.requiredEndDate}" >					
						<f:convertDateTime pattern="dd/MM/yyyy" />
						<f:passThroughAttribute name="required" value="true" />					
					</p:calendar>					
					
					<h:outputLabel id="contractPriceLabel" for="contractPrice"
						value="#{i18n.price}" />
					<h:inputText id="contractPrice" value="#{contractBean.contractNew.price}">
						<f:convertNumber minFractionDigits="2" />
					</h:inputText>
					
					<h:outputLabel id="contractCompanyLabel" for="contractCompany"
						value="#{i18n.company}" />
					<p:selectOneMenu value="#{contractBean.company}" 
						id="contractCompany" required="true" requiredMessage="#{i18n.requiredCompany}" 
						filter="true" filterMatchMode="startsWith"
						converter="#{companyConverterBean}" validator="#{companyValidator.validate}"> 								
						<f:passThroughAttribute name="required" value="true" />						
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listCompany}" var="c" itemLabel="#{c.name}" itemValue="#{c}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractProviderLabel" for="contractProvider"
						value="#{i18n.provider}" />
			        <p:selectOneMenu value="#{contractBean.provider}" required="true" requiredMessage="#{i18n.requiredProvider}" 
						id="contractProvider" filter="true" filterMatchMode="startsWith"
						converter="#{companyConverterBean}" validator="#{companyValidator.validate}"> 							
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listCompany}" var="p" itemLabel="#{p.name}" itemValue="#{p}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractApplicationLabel" for="contractApplication"
						value="#{i18n.applicationLabel}" />
			        <p:selectOneMenu value="#{contractBean.contractNew.application}" 
			        	required="true" requiredMessage="#{i18n.requiredApplication}" 
						id="contractApplication" filter="true" filterMatchMode="startsWith"
						converter="#{applicationConverterBean}" validator="#{applicationValidator.validate}"> 							
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listApplication}" var="a" itemLabel="#{a.name}" itemValue="#{a}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractStatusLabel" for="contractStatus"
						value="#{i18n.status}" />
					<h:panelGroup>
				        <p:selectOneMenu value="#{contractBean.contractNew.status}"
				        	required="true" requiredMessage="#{i18n.requiredStatus}"
							id="contractStatus" filter="true" filterMatchMode="startsWith"
							converter="#{statusConverterBean}" validator="#{statusValidator.validate}"> 							
							<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
				            <f:selectItems value="#{listBean.listStatus}" var="s" itemLabel="#{s.name}" itemValue="#{s}" />			           	            	
				        </p:selectOneMenu>
				        <ui:include src="status.xhtml" />
			        </h:panelGroup>
			        				
			        <h:outputLabel id="contractCommentsLabel" for="contractComments"
						value="#{i18n.commentsLabel}" />
					<p:inputTextarea id="contractComments" 
						value="#{contractBean.contractNew.comments}" rows="3" cols="19" />
																
					<f:facet name="footer">
			            <h:panelGroup style="display:block; text-align:center">
			                <p:commandButton id="createContractFormSubmit" action="#{contractBean.create}" value="#{i18n.submit}" 
			                	update=":contractForm:contractGrowl, :contractForm:dataTableAllContract,
			                	:createContractForm:newContractDialog" oncomplete="newContractDlg.hide()" />
			            </h:panelGroup>
			        </f:facet>				        	        			
				</h:panelGrid>		        
		    </p:dialog>			
		</h:form>	
		
		<!-- **************************************** Contract Details **************************************** -->
		
		<div class="span66">	
			<h:form id="detailContractForm" prependId="false">
				<p:panel header="#{i18n.contractDetailLabel}" id="panelDetailContract">
					<h:panelGrid columns="2">
						<h:outputLabel value="#{i18n.contractIdLabel}" />
						<h:outputText value="#{contractBean.contractView.idContract}" />
						
						<h:outputLabel value="#{i18n.contractNameLabel}" />
						<h:outputText value="#{contractBean.contractView.name}" />
						
						<h:outputLabel value="#{i18n.startDateLabel}" />
						<h:outputText value="#{contractBean.contractView.startDate}">
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText>
						
						<h:outputLabel value="#{i18n.endDateLabel}" />
						<h:outputText value="#{contractBean.contractView.endDate}">
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText>
												
						<h:outputLabel value="#{i18n.price}" />
						<h:outputText value="#{contractBean.contractView.price}">
							<f:convertNumber minFractionDigits="2" />
						</h:outputText>
						
						<h:outputLabel value="#{i18n.company}" />
						<h:outputText value="#{contractBean.company.name}" />
						
						<h:outputLabel value="#{i18n.provider}" />
						<h:outputText value="#{contractBean.provider.name}" />
						
						<h:outputLabel value="#{i18n.applicationLabel}" />
						<h:outputText value="#{contractBean.contractView.application.name}" />
						
						<h:outputLabel value="#{i18n.status}" />
						<h:outputText value="#{contractBean.contractView.status.name}" />
						
						<h:outputLabel value="#{i18n.commentsLabel}" />
						<h:outputText value="#{contractBean.contractView.comments}" />
						
						<f:facet name="footer">
							<p:commandButton id="showUpdateContract" value="#{i18n.update}" icon="ui-icon-wrench"
								action="#{contractBean.toggleUpdate}" oncomplete="updateContractDlg.show()"
								update=":updateContractForm:updateContractDialog" />
							<p:commandButton id="deleteContractSubmit" value="#{i18n.delete}" icon="ui-icon-trash"
								action="#{contractBean.delete}" update=":contractForm:contractGrowl,
								:contractForm:dataTableAllContract, :detailContractForm:panelDetailContract" />
						</f:facet>
					</h:panelGrid>
				</p:panel>
			</h:form>
		</div>
		
		<!-- **************************************** Dialog update contract **************************************** -->
	
	    <h:form id="updateContractForm">			     					      
		    <p:dialog id="updateContractDialog" header="#{i18n.updateContractLabel}" widgetVar="updateContractDlg" 
		    	dynamic="true" showEffect="clip" hideEffect="scale">					        
		        <h:panelGrid id="updateContractPanel" columns="2" styleClass="panel">					
					
					<h:outputLabel id="contractIdLabelUpdate" for="contractIdUpdate"
						value="#{i18n.contractIdLabel} " />						
					<h:inputText id="contractIdUpdate" value="#{contractBean.contractUpdate.idContract}">
						<f:passThroughAttribute name="required" value="true" />					
					</h:inputText>
					
					<h:outputLabel id="contractNameLabelUpdate" for="contractNameUpdate"
						value="#{i18n.contractNameLabel} " />						
					<h:inputText id="contractNameUpdate" value="#{contractBean.contractUpdate.name}">
						<f:passThroughAttribute name="required" value="true" />					
					</h:inputText>
					
					<h:outputLabel id="contractStartDateLabelUpdate" for="contractStartDateUpdate"
						value="#{i18n.startDateLabel}" />
					<p:calendar id="contractStartDateUpdate" value="#{contractBean.contractUpdate.startDate}" 
						pattern="dd/MM/yyyy" mode="popup" size="19" required="true" requiredMessage="#{i18n.requiredStartDate}" >					
						<f:convertDateTime pattern="dd/MM/yyyy" />
						<f:passThroughAttribute name="required" value="true" />					
					</p:calendar>
					
					<h:outputLabel id="contractEndDateLabelUpdate" for="contractEndDateUpdate"
						value="#{i18n.endDateLabel}" />
					<p:calendar id="contractEndDateUpdate" value="#{contractBean.contractUpdate.endDate}" 
						pattern="dd/MM/yyyy" mode="popup" size="19" required="true" requiredMessage="#{i18n.requiredEndDate}" >					
						<f:convertDateTime pattern="dd/MM/yyyy" />
						<f:passThroughAttribute name="required" value="true" />					
					</p:calendar>					
					
					<h:outputLabel id="contractPriceLabelUpdate" for="contractPriceUpdate"
						value="#{i18n.price}" />
					<h:inputText id="contractPriceUpdate" value="#{contractBean.contractUpdate.price}">
						<f:convertNumber minFractionDigits="2" />
					</h:inputText>
					
					<h:outputLabel id="contractCompanyLabelUpdate" for="contractCompanyUpdate"
						value="#{i18n.company}" />
					<p:selectOneMenu value="#{contractBean.company}" 
						id="contractCompanyUpdate" required="true" requiredMessage="#{i18n.requiredCompany}" 
						filter="true" filterMatchMode="startsWith"
						converter="#{companyConverterBean}" validator="#{companyValidator.validate}"> 								
						<f:passThroughAttribute name="required" value="true" />						
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listCompany}" var="c" itemLabel="#{c.name}" itemValue="#{c}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractProviderLabelUpdate" for="contractProviderUpdate"
						value="#{i18n.provider}" />
			        <p:selectOneMenu value="#{contractBean.provider}" required="true" requiredMessage="#{i18n.requiredProvider}" 
						id="contractProviderUpdate" filter="true" filterMatchMode="startsWith"
						converter="#{companyConverterBean}" validator="#{companyValidator.validate}"> 							
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listCompany}" var="p" itemLabel="#{p.name}" itemValue="#{p}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractApplicationLabelUpdate" for="contractApplicationUpdate"
						value="#{i18n.applicationLabel}" />
			        <p:selectOneMenu value="#{contractBean.contractUpdate.application}" 
			        	required="true" requiredMessage="#{i18n.requiredApplication}"
						id="contractApplicationUpdate" filter="true" filterMatchMode="startsWith"
						converter="#{applicationConverterBean}" validator="#{applicationValidator.validate}"> 							
						<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
			            <f:selectItems value="#{listBean.listApplication}" var="a" itemLabel="#{a.name}" itemValue="#{a}" />			           	            	
			        </p:selectOneMenu>
			        
			        <h:outputLabel id="contractStatusLabelUpdate" for="contractStatusUpdate"
						value="#{i18n.status}" />
					<h:panelGroup>
				        <p:selectOneMenu value="#{contractBean.contractUpdate.status}"
				      		required="true" requiredMessage="#{i18n.requiredStatus}"
							id="contractStatusUpdate" filter="true" filterMatchMode="startsWith"
							converter="#{statusConverterBean}" validator="#{statusValidator.validate}"> 							
							<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
				            <f:selectItems value="#{listBean.listStatus}" var="s" itemLabel="#{s.name}" itemValue="#{s}" />			           	            	
				        </p:selectOneMenu>
				        <ui:include src="status.xhtml" />
			        </h:panelGroup>
			        				
			        <h:outputLabel id="contractCommentsLabelUpdate" for="contractCommentsUpdate"
						value="#{i18n.commentsLabel}" />
					<p:inputTextarea id="contractCommentsUpdate" 
						value="#{contractBean.contractUpdate.comments}" rows="3" cols="19" />
																
					<f:facet name="footer">
			            <h:panelGroup style="display:block; text-align:center">
			                <p:commandButton id="updateContractFormSubmit" action="#{contractBean.update}" value="#{i18n.submit}" 
			                	update=":contractForm:contractGrowl, :contractForm:dataTableAllContract, :detailContractForm:panelDetailContract,
			                	:updateContractForm:updateContractDialog" oncomplete="updateContractDlg.hide()" />
			            </h:panelGroup>
			        </f:facet>				        	        			
				</h:panelGrid>		        
		    </p:dialog>			
		</h:form>	
	</ui:define>
	
</ui:composition>
</html>